package com.guoji.cameracall

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.guoji.cameracall.client.VideoCallClientActivity
import com.guoji.cameracall.databinding.ActivityCallClientBinding
import com.guoji.cameracall.databinding.ActivityMainBinding
import com.guoji.cameracall.server.VideoCallServerActivity


/**
 * 视频通话
 */

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        checkPermission()
        binding.btCallClient.setOnClickListener {
            startActivity(Intent(this, VideoCallClientActivity::class.java))
        }
        binding.btCallServer.setOnClickListener {
            startActivity(Intent(this, VideoCallServerActivity::class.java))
        }
    }

    private fun checkPermission(): Boolean {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            requestPermissions(
                arrayOf(
                    Manifest.permission.CAMERA,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.ACCESS_WIFI_STATE
                ), 1
            );

        }
        return false
    }
}